package cdc.retrofit.official.jsonqueryparameters;

import java.io.IOException;
import okhttp3.ResponseBody;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class JsonQueryParameters {
	public static void main(String... args) throws IOException, InterruptedException {
		MockWebServer server = new MockWebServer();
		server.start();
		server.enqueue(new MockResponse());

		Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/"))
				.addConverterFactory(new JsonStringConverterFactory(GsonConverterFactory.create())).build();
		Service service = retrofit.create(Service.class);

		Call<ResponseBody> call = service.example(new Filter("123"));
		Response<ResponseBody> response = call.execute();
		// TODO handle user response...

		// Print the request path that the server saw to show the JSON query param:
		RecordedRequest recordedRequest = server.takeRequest();
		System.out.println(recordedRequest.getPath());

		server.shutdown();
	}
}
